﻿namespace Web.Control.WWW.Course
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text.RegularExpressions;
    using System.IO;
    using Lx.Web.Common.ControlsUI;
    using Lx.Web.Common.UI;
    using BLF;
    using System.Collections.Generic;
using Model.WWW_User.Teach;

    public class CSession : BaseControl
    {        
        protected long CID;
        /// <summary>
        /// Course信息
        /// </summary>
        protected CoursesModel CourseInfo;
        protected Repeater rptSessions;
        /// <summary>
        /// 列表大小
        /// </summary>
        protected Literal litCount;
        protected int RecordCount = 0;
        protected int PageIndex = 1;
        protected int PageSize = 15;

        protected override void OnLoad(EventArgs e)
        {            
            if(string.IsNullOrEmpty(Request["cid"]))
            {
                Response.End();
                return;
            }
            long.TryParse(Request["cid"],out CID);
            if (!string.IsNullOrEmpty(Request["p"]))
            {
                if (Request["p"] == "L")
                {
                    PageIndex = 999;
                }
                else
                {
                    int.TryParse(Request["p"], out PageIndex);
                }
            }
            int.TryParse(litCount.Text, out PageSize);
            ArrayList arrList = BLF.WWW_User.Teach.Teach.GetACourseSessions(CID, PageIndex, PageSize);
            
            if (arrList != null)
            {
                CourseInfo = arrList[0] as CoursesModel;
                RecordCount = (int)arrList[1];
                int pCount = (int)Math.Ceiling(((decimal)RecordCount) / ((decimal)PageSize));
                if (PageIndex > pCount) PageIndex = pCount;
                
                if (rptSessions != null)
                {
                    rptSessions.DataSource = arrList[2];
                    rptSessions.DataBind();
                }
                //title
                this.DynamicTitle = GetText("{0}: Sessions - italki {1} Courses", new string[] { CourseInfo.Title, BLF.StaticData.GetLanguageText(CourseInfo.LanguageLearn) });
                this.DynamicKeywords = GetText("{0}, session, course, {1}", new string[] { CourseInfo.Title, BLF.StaticData.GetLanguageText(CourseInfo.LanguageLearn) });
                this.DynamicDescription = GetText("Latest sessions of {0} at italki", new string[] { CourseInfo.Title });
            }
            else {
                Response.End();
                return;
            }
        }                
    }
}


